package com.douziit.meilianoa.base.utils.file;

import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * @author MrShun
 * @version 1.0
 */
public class FileTypeUtil {

    private static final List<String> allowImageType = Arrays.asList("image/bmp", "image/png", "image/gif", "image/jpg", "image/jpeg");

    private static final List<String> allowVideoType = Arrays.asList("video/mpeg4","video/mp4","video/mov","video/wmv","video/avi","video/asf","video/navi","video/3gp","video/ext-mp4");


    /**
     * 校验文件是否为图片
     *
     * @param files 文件对象
     * @return
     */
    public static boolean checkImage(MultipartFile... files) {
        for (MultipartFile file : files) {
            if (!allowImageType.contains(file.getContentType())) {
                return false;
            }
        }
        return true;
    }

    /**
     * 校验视频文件格式
     *
     * @param files 文件对象
     * @return
     */
    public static boolean checkVideo(MultipartFile... files) {
        for (MultipartFile file : files) {
            if (!allowVideoType.contains(file.getContentType())) {
                return false;
            }

        }
        return true;
    }


}
